package com.zzt.zt_glideapputil

import android.os.Bundle
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.zzt.glideapp.GlideAppUtils
import com.zzt.glideapp.RoundedCornersTransformation
import com.zzt.glideapp.GlideSizeUtils
import com.zzt.zt_glideapputil.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {
    var imgUrl =
        "http://test-cdn.daily-fx.net/images/group/post/1272cc03-a3b9-4a65-9938-ae7d4c8555b5.jpg"

    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initView()
    }

    private fun initView() {
        addImageView()


        GlideAppUtils.getInstance().loadRoundCircleImageV1(
            baseContext,
            imgUrl,
            binding.ivTop,
            20F
        )


        GlideAppUtils.getInstance().loadCircleWithBorderImage(
            baseContext,
            imgUrl,
            binding.ivTop1,
            10f,
            ContextCompat.getColor(
                baseContext,
                R.color.greenyellow
            )
        )
    }

    fun addImageView() {
        for (k in 0..20) {
            var childImg = ImageView(baseContext)
            var params = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                GlideSizeUtils.dp2px(baseContext, 200f)
            )
            params.topMargin = GlideSizeUtils.dp2px(baseContext, 30f)
            when (k) {
                0 -> {
                    GlideAppUtils.getInstance().loadImage(baseContext, imgUrl, childImg)
                }
                1 -> {
                    GlideAppUtils.getInstance().loadImageSize(
                        baseContext,
                        imgUrl,
                        childImg,
                        GlideSizeUtils.dp2px(baseContext, 100f),
                        GlideSizeUtils.dp2px(baseContext, 150f)
                    )
                }
                2 -> {
                    GlideAppUtils.getInstance().loadCircleImage(
                        baseContext,
                        imgUrl,
                        childImg
                    )
                }
                3 -> {
                    GlideAppUtils.getInstance().loadCircleWithBorderImage(
                        baseContext,
                        imgUrl,
                        childImg,
                        10f,
                        ContextCompat.getColor(
                            baseContext,
                            R.color.greenyellow
                        )
                    )
                }
                4 -> {
                    GlideAppUtils.getInstance().loadRoundCircleImage(
                        baseContext,
                        imgUrl,
                        childImg,
                        10f, RoundedCornersTransformation.CornerType.ALL
                    )
                }
                5 -> {

                }
                6 -> {

                }
                7 -> {

                }
                8 -> {
                    GlideAppUtils.getInstance().loadRoundCircleImage(
                        baseContext,
                        imgUrl,
                        childImg,
                        20f
                    )
                }
                9 -> {
//                    GlideAppUtils.getInstance().loadRoundCircleImageV1(
//                        baseContext,
//                        imgUrl,
//                        childImg,
//                        20F
//                    )
                }
                10 -> {
                    GlideAppUtils.getInstance().loadSquareImage(
                        baseContext,
                        imgUrl,
                        childImg
                    )
                }
                11 -> {

                }

            }
            binding.llImgList.addView(childImg, params)
        }
    }
}